package stu.day1_day8;

import java.util.ArrayDeque;

public class LeetCode946 {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
        int j = 0;
        for(int i=0;i<pushed.length;i++){
            stack.push(pushed[i]);

            while(!stack.isEmpty() && stack.peek()==popped[j]){
                stack.pop();
                j += 1;
            }
        }

        return stack.isEmpty();

    }


}
